<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2018/4/19
 * Time: 14:59
 */

namespace app\index\controller;


use think\Controller;

class Doctors extends GetSlides
{
    public function doctor_nav()
    {
        $cates = [
            ['id' => '2728580c-06fc-4169-ad43-9ec1408f99f0', 'type' => 'department'],//诊疗中心
            ['id' => 'f7d007e6-401d-45c5-9919-72f12b94ca6d', 'type' => 'department'],//非手术科室
            ['id' => '5884bf44-192c-4113-9a59-1c840601f55b', 'type' => 'department'],//手术科室
            ['id' => '693e9cc3-7ff6-43b5-a376-795a590ddf5a', 'type' => 'department'],//平台科室
        ];
        $A = new Api();
        $n = 0;//2级科室
        $j = 0;//1级科室
        $h = 0;//判断医生属于哪个科室
        $doctors_data = $A->get_menu('doctors');
        $_data = $A->get_menu('departments');
        $_data = getImg($_data);
        foreach ($cates as $key => $value) {

            for ($i = 0; $i < count($_data['data']); $i++) {
                if ($_data['data'][$i]['relationships']['parent']['data']) {
                    if ($_data['data'][$i]['relationships']['parent']['data'][0]['id'] == $value['id']) {

                        $department2[$n] = [
                            'id' => $_data['data'][$i]['id'],
                            'name' => $_data['data'][$i]['attributes']['name'],
                        ];
                        for ($d = 0; $d < count($doctors_data['data']); $d++) {
                            if ($doctors_data['data'][$d]['relationships']['department']['data']['id'] == $_data['data'][$i]['id']) {
                                $department2[$n]['children']['children' . $h] = [
                                    'name' => $doctors_data['data'][$d]['attributes']['name'],
                                    'id' => $doctors_data['data'][$d]['id'],
                                    'department' => $_data['data'][$i]['id']
                                ];
                                $h++;
                            }
                        }
                        if (!isset($department2[$n]['children'])) {  //没有医生时候
                            $department2[$n]['children']['children0'] = [
                                'name' => '',
                                'id' => '',
                                'department' => ''
                            ];
                        }
                        $n++;
                    }
                }
            }
            $n = 0;
            $key = 'department' . ($j + 1);
            $j++;
            $data[$key] = [
                'id' => $value['id'],
                'list' => $department2,
            ];
        }
        $this->assign($data);
        $this->assign("web_title", "医生列表");

        return view();
    }

    public function leader_doctor()
    {
        $A = new Api();
        $doctor = $A->get_leader_detail(input('get.id'));
        $doctor = getImg($doctor);
        $this->assign("doctor", $doctor['data']);
        return view();
    }
}